package com.baijiayun.liveuibase.widgets.dialog;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import androidx.annotation.NonNull;
import com.baijiayun.liveuibase.R;
import org.jetbrains.annotations.NotNull;

/**
 * 标准提示弹框（顶栏 + 文字提示说明 + 确认/取消按钮）
 * todo 替换CommonDialog?
 */
public class SimpleTipsDialog extends BaseTitleDialog {

    public enum ChoiceMode {
        None(0),
        Single_Positive(1),
        Single_Negative(2),
        Double(3);
        int mode;

        ChoiceMode(int mode) {
            this.mode = mode;
        }
    }

    private ChoiceMode choiceMode = ChoiceMode.Double;
    //确认按钮文案
    private String positiveText;
    //取消按钮文案
    private String negativeText;
    //提示标题
    private String contentTitle;
    //提示正文
    private String contentText;
    private View.OnClickListener onPositiveClickListener;
    private View.OnClickListener onNegativeClickListener;

    public SimpleTipsDialog(@NonNull @NotNull Context context) {
        super(context);
    }

    public SimpleTipsDialog setTips(String title, String content) {
        contentTitle = title;
        contentText = content;
        return this;
    }

    public SimpleTipsDialog setDisplayMode(ChoiceMode choiceMode) {
        this.choiceMode = choiceMode;
        return this;
    }

    public SimpleTipsDialog setPositive(String positiveText, View.OnClickListener onPositiveClickListener) {
        this.positiveText = positiveText;
        this.onPositiveClickListener = onPositiveClickListener;
        return this;
    }

    public SimpleTipsDialog setNegative(String negativeText, View.OnClickListener onNegativeClickListener) {
        this.negativeText = negativeText;
        this.onNegativeClickListener = onNegativeClickListener;
        return this;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window dialogWindow = getWindow();
        if (dialogWindow != null) {
            WindowManager.LayoutParams params = dialogWindow.getAttributes();
            params.width = (int) getContext().getResources().getDimension(R.dimen.bjy_base_live_tips_dialog_width);
            params.height = (int) getContext().getResources().getDimension(R.dimen.bjy_base_live_tips_dialog_height);
            dialogWindow.setAttributes(params);
        }
        switch (choiceMode) {
            case None:
                $.id(R.id.simple_tips_dialog_negative).visibility(View.GONE);
                $.id(R.id.simple_tips_dialog_positive).visibility(View.GONE);
                break;
            case Single_Negative:
                $.id(R.id.simple_tips_dialog_positive)
                        .visibility(View.GONE)
                        .id(R.id.simple_tips_dialog_negative)
                        .text(negativeText)
                        .visibility(View.VISIBLE)
                        .view()
                        .setOnClickListener(onNegativeClickListener);
                break;
            case Single_Positive:
                $.id(R.id.simple_tips_dialog_negative)
                        .visibility(View.GONE)
                        .id(R.id.simple_tips_dialog_positive)
                        .text(positiveText)
                        .visibility(View.VISIBLE)
                        .view()
                        .setOnClickListener(onPositiveClickListener);
                break;
            case Double:
                $.id(R.id.simple_tips_dialog_positive)
                        .text(positiveText)
                        .view()
                        .setOnClickListener(onPositiveClickListener);

                $.id(R.id.simple_tips_dialog_negative)
                        .text(negativeText)
                        .view()
                        .setOnClickListener(onNegativeClickListener);
                break;
            default:
                break;
        }
        $.id(R.id.simple_tips_title)
                .text(contentTitle)
                .visibility(TextUtils.isEmpty(contentTitle) ? View.GONE : View.VISIBLE);

        $.id(R.id.simple_tips_content)
                .text(contentText)
                .visibility(TextUtils.isEmpty(contentText) ? View.GONE : View.VISIBLE);

    }

    @Override
    protected int getContentLayout() {
        return R.layout.uibase_simple_tips_dialog;
    }
}
